define(['app'], function(app) {
    app.controller('SearchController', ['$routeParams', 'Table', 'SearchService',
        function($routeParams, Table, SearchService) {
        var self = this;
        self.keyword = $routeParams.keyword;

        self.init = function() {
            angular.element('#keyword').val(self.keyword);
        };

        self.tableParams = Table.$create({
            count: 15,
            pageable: true
        }, {
            counts: [],
            getPageData: function(params) {
                return SearchService.getResultByPage({
                    keyword: self.keyword,
                    offset: params.offset,
                    limit: params.limit,
                    orderBy: params.orderBy()
                }).then(function(resp) {
                    params.total(resp.data.total);
                    return resp.data.data;
                });
            }
        });
    }]);
});